
%adaboost train and classify

clear all
close all
clc
accuracy = [];
features = {'../flv1.mat','../flv2.mat','../flv3.mat','../flv4.mat','../flv5.mat'};
fileIndex = fileIndex[1 2 3 4 5];
featSize = size(features,2);
h1 = waitbar(0);
h2 = waitbar(0);
for outerIndex = 1:size(features,2)
    allfeat = [];
    alllabel = [];    
    waitbar(outerIndex/featSize,h1,sprintf('Outer Index %d',outerIndex));
    for subj = 1 : (size(features,2)-1)
        load(features{subj});
        allfeat=[allfeat; feat];
        alllabel= [alllabel;label];
    end
    % xtrain - The training data. RxC Rows - number of samples, Columns - the
    % dimension of the samples.
    % ytrain - The labels associated with the training data - Rx1 vector.
    % nLabel - The number of classes.
    % nIter - The maximum number of boosting iterations.

    xtrain= allfeat;
    ytrain= alllabel;
    nLabel=5;
    nIter=300;


    multiclass_model = trainadaboost(xtrain,ytrain,nLabel,nIter,h2);


    % xtest - the data that needs to be classified 1xC vector.
    % multiclass_model - the multi class trained adaboost model
    % label - The classified label.
    % This function classifies the test data using the trained adaboost model
    % and returns the label.

    %Test the remaining subject data with the model
    xtest= [];
    subj = size(features,2);
        load(features{subj});

        test_correct_count=0;
       % feat has the features of the subj 
    for i=1:size(feat,1)
       xtest = feat(i,:);
       knownlabel= label(i);

    testlabel = classifyadaboost(xtest,multiclass_model);
    disp(knownlabel);
     disp(testlabel);
     if (testlabel== knownlabel)
         test_correct_count= test_correct_count+1;
     end
    end
    accuracy = [accuracy;[fileIndex(subj) test_correct_count/size(feat,1)]];
    features = circshift(features,[0,1]);
    fileIndex = circshift(fileIndex,[0,1]);
end
close(h1);

